﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Text;
using System.Security.Cryptography;
using System.IO;

using CE.Global;
using CE.Database;
using CE.Configuration;


public partial class savings_thankyou : MyLanguageBasePage
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    string selectedLanguage;
    protected void Page_Load(object sender, EventArgs e)
    {
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");
        if (_strCXLive == "0")
        {
            if (Session[CE.Global.General.Guest] == null)
            {
                Response.Redirect("~/Default");
            }

        }
        Page.Header.Title = Resources.FWD.Thankyou;

        HtmlLink css = new HtmlLink();
        css.Href = Resources.FWD.CssSavingsUrl;
        css.Attributes["rel"] = "stylesheet";
        css.Attributes["type"] = "text/css";
        css.Attributes["media"] = "all";
        Page.Header.Controls.Add(css);


        if (!Page.IsPostBack)
        {
            lblMessage.Text = "";
            ibtnLanguage.ImageUrl = Resources.FWD.ImgLanguageUrl;
            hplHome.NavigateUrl = CE.Global.General.GetUrl("/", Page);
            Uri theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl);
            string rq_type = HttpUtility.ParseQueryString(theRealURL.Query).Get("type");
            if (rq_type != null && rq_type != string.Empty)
            {
                if (rq_type.ToString().ToLower() == "call")
                {
                    lblMessage.Text = Resources.FWD.CallMeThankYou;
                }
                else if (rq_type.ToString().ToLower() == "email")
                {
                    lblMessage.Text = Resources.FWD.EmailThankYou;
                }
            }
        }
    }

    protected void ibtnLanguage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        selectedLanguage = string.Empty;

        //if (hdnLanguage.Value != string.Empty)
        //{
        //    Session["Language"] = hdnLanguage.Value;
        //}

        if (Session["Language"] != null)
        {
            selectedLanguage = Session["Language"].ToString();
        }
        else
        {
            selectedLanguage = "th-TH";
            Session["Language"] = selectedLanguage;
        }

        if (selectedLanguage == "th-TH")
        {
            Session["Language"] = "en-US";
        }
        else
        {
            Session["Language"] = "th-TH";
        }

        hdnLanguage.Value = selectedLanguage;
        if (selectedLanguage == "en-US")
        {
            Response.Redirect(Request.UrlReferrer.AbsoluteUri.Replace("/en", ""));
        }
        else
        {
            string[] _arrList = Request.UrlReferrer.AbsoluteUri.Split('/');
            string _redirectUrl = "";
            _arrList[3] = "en/" + _arrList[3];
            for (int i = 0; i < _arrList.Length; i++)
            {

                if (i != _arrList.Length - 1)
                {
                    _redirectUrl += _arrList[i].ToString() + "/";
                }
                else
                {
                    _redirectUrl += _arrList[i].ToString();
                }

            }
            if (_arrList.Length == 4 && _redirectUrl.EndsWith("/"))
            {
                _redirectUrl += "home";
            }

            Response.Redirect(_redirectUrl);
        }
    }

    protected void btnSearchAgain_Click(object sender, EventArgs e)
    {
        string _redirectUrl = "";
        _redirectUrl = CE.Global.General.GetUrl("~/savings/life-insurance", Page);
        Response.Redirect(_redirectUrl);
    }

}
